package com.action;

/**
 * <p>功能描述:分页相关数据bean</p>
 * @author  <a href="mailto: timilder@yeah.net">timilder</a>
 * @create_date Sep 24, 2007
 * @version $ Revision: 1.0
 */
public class PageBean {
	
	public static final int PAGE_SIZE = 10;
	
	int total;
	int page;
	int pageSize;
	
	int totalPage;
	String hql;
	public PageBean(int total,int page,int pageSize){
		this.total = total;
		this.page = page;
		this.pageSize = pageSize;
		init();
	}
	
	public PageBean(int total,int page){
		this.total = total;
		this.page = page;
		this.pageSize = PAGE_SIZE;
		init();
	}
	
	void init(){
		if(page<1)
			page = 1;
		if(total<0)
			total = 0;
		if(pageSize<1)
			pageSize = PAGE_SIZE;
		totalPage = (total-1)/pageSize + 1;
		if(totalPage<page){
			page=totalPage;
		}
	}

	public int getPage() {
		return page;
	}

	public int getPageSize() {
		return pageSize;
	}

	public long getTotal() {
		return total;
	}

	public int getTotalPage() {
		return totalPage;
	}
	
	public int getPrePage(){
		if(total >0){
			if(page<2)
				return 1;
			return page-1;
		}
		return 0;
	}
	
	public int getNextPage(){
		if(page>=totalPage)
			return totalPage;
		return page+1;
	}
	
	public int getFirst(){
		if(page<1)
			return 1;
		return (page-1)*pageSize;
	}
	
	public int getFirstPage(){
		if(total>0)
			return 1;
		return 0;
	}

	public String getHql() {
		return hql;
	}

	public void setHql(String hql) {
		this.hql = hql;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public void setTotal(int total) {
		this.total = total;
	}
	
	
}
